//
//  YSBaseDemoListViewController.m
//  YSKitDemo
//
//  Created by Kyson on 2018/12/14.
//  Copyright © 2018 YangShen. All rights reserved.
//

#import "YSBaseDemoListViewController.h"

@interface YSBaseDemoListViewController ()

@end

@implementation YSBaseDemoListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}


- (void)setItems:(NSMutableArray<YSDemoItem *> *)items {
    _items = items;
    [self.tableView reloadData];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.items count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    YSDemoItem *item = self.items[indexPath.row];
    cell.textLabel.text = item.title;
    cell.detailTextLabel.text = item.subtitle;
    
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    YSDemoItem *item = self.items[indexPath.row];
    UIViewController *vc = [item.aClass new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
